<template>
  <div class="app-container">
    <!-- 查询 -->
    <tl-list-search ref="search" :query-param="queryParam" @search="doQuery" :isDisplayDefaultSearch="false" v-if="isHeaderDisplay">
      <template slot="search"> </template>
    </tl-list-search>
    <!-- 工具栏 -->
    <tl-list-toolbar ref="toolbar" @add="openAddDialog('editForm')" :isDisplayRight="false" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :isDisplayExport="false" :disableDeleteBatch="selectedRowKeys.length <= 0" :addPermission="this.addPermission" :deletePermission="['pm:cbbPmDeliverable:delete']">
      <template slot="left-btn"> </template>
    </tl-list-toolbar>
    <div>
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight - appointHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="selection" width="55px" fixed="left" :selectable="doDisableCheckBox"></el-table-column>
        <el-table-column prop="code" label="交付物编码" width="150px" sortable="custom" sort-by="code" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="name" label="交付物名称" width="300px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispdeliverabletype" label="交付物类型" width="250px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispcreateuser" label="提交人" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispsourcemodule" label="来源" width="150px" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="open" label="是否公开" width="100px" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.open === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column label="操作" width="200px" v-slot="scope" fixed="right">
          <el-button type="text" icon="el-icon-edit" @click="openEditDialog('editForm', scope.row.id)" :disabled="scope.row.sourcemodule === '02'" v-hasPermission="editPermission">编辑</el-button>
          <el-button type="text" icon="el-icon-delete" @click="doDelete(scope.row.id)" :disabled="scope.row.sourcemodule === '02'" v-hasPermission="['pm:cbbPmDeliverable:delete']">删除</el-button>
          <el-button type="text" icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看</el-button>
        </el-table-column>
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-edit ref="editForm" @refresh="doRefresh" :projectcode="this.projectcode"></tl-edit>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
import { checkPermission } from '@tapui/utils/permission'
/** 子组件 */
import tlEdit from './edit'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'cbbPmDeliverable',
  mixins: [mixin_list],
  components: { tlEdit },
  data() {
    return {
      description: '项目交付物-列表查询',
      urlPrefix: '/cbb/pmDeliverable/',
      url: {
        queryCodeList: '/cbb/pmDeliverable/dataCodeList'
      },
      // 排序参数
      sorterInfo: {
        sidx: 'id',
        sord: 'desc'
      },
      isHeaderDisplay: false,
      isQueryOnCreated: false,
      projectcode: '',
      addPermission: ['pm:cbbPmDeliverable:add'],
      editPermission: ['pm:cbbPmDeliverable:edit']
    }
  },
  props: {
    /** 项目号 */
    // projectcode: {
    //   type: String
    // }
    appointHeight: {
      type: Number,
      default: 0
    }
  },
  mounted() {
    // this.$set(this.queryParam, 'projectcode', this.projectcode)
    // this.doQuery()
  },

  methods: {
    // 禁用表格前面的选择
    doDisableCheckBox(row, index) {
      if (row.sourcemodule === '02') {
        return false
      } else {
        return true
      }
    },
    pageInit(projectcode) {
      this.projectcode = projectcode
      this.$set(this.queryParam, 'projectcode', this.projectcode)
      this.doQuery()
    },
    /** 表格双击事件 */
    doRowDbClick(row, column, event) {
      if (row.sourcemodule === '02') {
        this.rowDbClickActionType = 'view'
      } else {
        this.rowDbClickActionType = 'edit'
      }
      if (this.rowDbClickActionType === 'edit') {
        // 判断是否有权限
        if (this.editPermission.length > 0) {
          if (checkPermission(this.editPermission)) {
            this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
          } else {
            this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
          }
        } else {
          this.openEditDialog('editForm', row[this.$refs.mainTable.rowKey])
        }
      } else if (this.rowDbClickActionType === 'view') {
        this.openViewDialog('editForm', row[this.$refs.mainTable.rowKey])
      }
    }
  }
}
</script>

<style scoped></style>
